home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / recvfax / alter.c next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  128 lines

  1. /*    $Header: /usr/people/sam/fax/recvfax/RCS/alter.c,v 1.14 1994/04/04 18:25:18 sam Rel $
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #include "defs.h"
  26. #include <sys/file.h>
  27. #include <stdarg.h>
  28.  
  29. /*
  30.  * Setup a job's description file for alteration.
  31.  */
  32. static FILE*
  33. setupAlteration(Job* job, const char* jobname)
  34. {
  35.     FILE* fp = fopen(job->qfile, "a+");
  36.     if (fp == NULL) {
  37.     syslog(LOG_ERR, "alter: cannot open %s (%m)", job->qfile);
  38.     sendClient("openFailed", "%s", jobname);
  39.     return (fp);
  40.     }
  41.     if (flock(fileno(fp), LOCK_EX|LOCK_NB) < 0) {
  42.     syslog(LOG_INFO, "%s locked during alteration (%m)", job->qfile);
  43.     sendClient("jobLocked", "%s", jobname);
  44.     fclose(fp);
  45.     return (NULL);
  46.     }
  47.     return (fp);
  48. }
  49.  
  50. static int
  51. reallyAlterJob(Job* job, const char* jobname, char* tag, const char* item)
  52. {
  53.     if (item) {
  54.     FILE* fp = setupAlteration(job, jobname);
  55.     if (fp) {
  56.         fprintf(fp, "%s:%s\n", tag, item);
  57.         (void) flock(fileno(fp), LOCK_UN);
  58.         (void) fclose(fp);
  59.         syslog(LOG_INFO, "ALTER %s %s %s completed", job->qfile, tag, item);
  60.         sendClient("altered", "%s", jobname);
  61.         return (1);
  62.     }
  63.     } else
  64.     protocolBotch("no %s specification.", tag);
  65.     return (0);
  66. }
  67.  
  68. static void
  69. cvtTimeToAscii(const char* spec, char* buf, const char* what)
  70. {
  71.     u_long when;
  72.  
  73.     if (!cvtTime(spec, &now, &when, what)) {
  74.     done(1, "EXIT");
  75.     /*NOTREACHED*/
  76.     }
  77.     sprintf(buf, "%lu", when);
  78. }
  79.  
  80. static void
  81. reallyAlterJobTTS(Job* job, const char* jobname, const char* spec)
  82. {
  83.     char tts[20];
  84.     cvtTimeToAscii(spec, tts, "time-to-send");
  85.     if (reallyAlterJob(job, jobname, "tts", tts))
  86.     notifyServer(job->modem, "JT%s %s", job->qfile, tts);
  87. }
  88. void
  89. alterJobTTS(const char* modem, char* tag)
  90. {
  91.     applyToJob(modem, tag, "alter", reallyAlterJobTTS);
  92. }
  93.  
  94. static void
  95. reallyAlterJobKilltime(Job* job, const char* jobname, const char* spec)
  96. {
  97.     char killtime[20];
  98.     cvtTimeToAscii(spec, killtime, "kill-time");
  99.     (void) reallyAlterJob(job, jobname, "killtime", killtime);
  100. }
  101. void
  102. alterJobKillTime(const char* modem, char* tag)
  103. {
  104.     applyToJob(modem, tag, "alter", reallyAlterJobKilltime);
  105. }
  106.  
  107. static void
  108. reallyAlterJobMaxDials(Job* job, const char* jobname, const char* max)
  109. {
  110.     (void) reallyAlterJob(job, jobname, "maxdials", max);
  111. }
  112. void
  113. alterJobMaxDials(const char* modem, char* tag)
  114. {
  115.     applyToJob(modem, tag, "alter", reallyAlterJobMaxDials);
  116. }
  117.  
  118. static void
  119. reallyAlterJobNotification(Job* job, const char* jobname, const char* note)
  120. {
  121.     (void) reallyAlterJob(job, jobname, "notify", note);
  122. }
  123. void
  124. alterJobNotification(const char* modem, char* tag)
  125. {
  126.     applyToJob(modem, tag, "alter", reallyAlterJobNotification);
  127. }
  128.